package com.qianxun.module.datasource1.admin.view;

import com.qianxun.module.datasource1.admin.entity.SysDataModifyLock;
import com.qianxun.module.datasource1.admin.service.SysDataModifyLockService;
import com.qianxun.module.base.view.BaseViewController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @author: huwei
 * @date: 2019/11/13 15:05
 * @version: 1.0.0
 */
@Controller
@RequestMapping(value = {"/admin/dataModifyLock"})
public class SysDataModifyLockController extends BaseViewController {
    private static final String  VIEW_PAGE_PREFIX = "module/admin/sysDataModifyLock";

    @Resource
    private SysDataModifyLockService sysDataModifyLockService;

    @Override
    protected String prefix() {
        return VIEW_PAGE_PREFIX;
    }

    @RequestMapping(value = {"/toDataLock"})
    public ModelAndView toDataLock(ModelAndView modelAndView ,@RequestParam("dataKey") String dataKey){
        SysDataModifyLock old = sysDataModifyLockService.getByDataKey(dataKey);
        boolean isLocked = old != null;
        modelAndView.setViewName(prefix().concat("/index.html"));
        modelAndView.addObject("isLocked" ,isLocked);
        modelAndView.addObject("dataKey" ,dataKey);
        return modelAndView;
    }
}
